﻿<%@ Page Language="C#" MasterPageFile="~/Admin/admin.master" AutoEventWireup="true"
    CodeFile="PaymentEdit.aspx.cs" Inherits="PaymentEdit" Title="Payment Edit" %>

<%@ MasterType TypeName="Admin_admin" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    Payment - Add/Edit</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script src="https://www.google.com/jsapi" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">
        google.load("language", "1");
        var apiKey = "AIzaSyCmYKgS2nT4WLhK0XoIvvmH5vFxTcxdffs";

        function OpenPopup() {
            $("#dialog").dialog("open");
            return false;
        }

        function openDialog(message) {
            $("#message").dialog({
                modal: true,
                buttons: {
                    Ok: function() {
                        $(this).dialog("close");
                    }
                }
            });
            return false;
        }
        
        function TranslateText(e) {

            var text = $.trim($(e).val());
            var translatedText = $('#<%=dataDescriptionVN.ClientID %>').val();
            if (text.length > 0 && translatedText.length == 0) {
                var apiurl = "https://www.googleapis.com/language/translate/v2?key=" + apiKey + "&source=en&target=vi&q=";

                $.ajax({
                    url: apiurl + encodeURIComponent(text),
                    dataType: 'jsonp',
                    async: false,
                    success: function(data) {
                        try {
                            $('#<%=dataDescriptionVN.ClientID %>').val(data.data.translations[0].translatedText);
                        }
                        catch (e) {
                            $('#<%=dataDescriptionVN.ClientID %>').val(text);
                        }
                        //$('#divTranslated').css({ "border": "1px solid #7F9DB9" });
                        //$('#divTranslated').css({ "padding": "4 4 4 4" });

                        //$('#lblTranslation').css({ "color": "black" });
                    },
                    error: function(x, e) {
                        alert('Error occured while translating the text');
                    }
                });
            }
            else {
                ;
                //$.unblockUI();
            }
            //$.unblockUI();
        };
        
        // Funtion run after ajax postback
        function contentPageLoad() {
            $('#<%=dataAccountCode.ClientID%>_chosen').find('a.chosen-single').focus();
            //console.log('focused!');
            //$('#<%=btnCancel.ClientID %>').focus();
            //console.log('focused!');
            //$('#<%=btnCancel.ClientID %>').focusout(function() {
            //    console.log('lost focused!');
            //});  
        }
        
        		
    </script>

    <data:MultiFormView ID="FormView1" DataKeyNames="PaymentId" runat="server" DataSourceID="PaymentDataSource"
        Width="600px" OnLoad="FormView1_Load" OnItemCommand="FormView1_ItemCommand">
        <EditItemTemplatePaths>
            <data:TemplatePath Path="~/Admin/UserControls/PaymentFields.ascx" />
        </EditItemTemplatePaths>
        <InsertItemTemplatePaths>
            <data:TemplatePath Path="~/Admin/UserControls/PaymentFields.ascx" />
        </InsertItemTemplatePaths>
        <EmptyDataTemplate>
            <b>Payment not found!</b>
        </EmptyDataTemplate>
        <FooterTemplate>
            <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert" CssClass="button" ValidationGroup="Entity" />
            <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update" CssClass="button" ValidationGroup="Entity" />
            <asp:Button ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel" CssClass="button" />
            <a rel="modal" href="#messages"><span class="button" id="VoidButton" runat="server">
                Void</span></a>
            <input type="button" id="CloneButton" value="Clone" onclick="javascript:OpenPopup();" class="button" runat="server">
            <asp:Button ID="PreviewButton" runat="server" CausesValidation="False" CommandName="Print"
                Visible="False" Text="Print" CssClass="button" />
            <asp:Button runat="server" ID="btnPayment" OnClientClick="javascript:location.href='PaymentEdit.aspx'; return false;"
                Text="New Voucher" CssClass="button"></asp:Button>
        </FooterTemplate>
    </data:MultiFormView>
    <data:PaymentDataSource ID="PaymentDataSource" runat="server" SelectMethod="GetByPaymentId"
        OnInserting="PaymentDataSource_Inserting">
        <Parameters>
            <asp:QueryStringParameter Name="PaymentId" QueryStringField="PaymentId" Type="String" />
        </Parameters>
    </data:PaymentDataSource>
    <br />
    <div id="messages" style="display: none">
        <!-- Messages are shown when a link with these attributes are clicked: href="#messages" rel="modal"  -->
        <h4>
            Void Reason</h4>
        <fieldset>
            <asp:TextBox runat="server" ID="dataVoidReason" TextMode="MultiLine" CssClass="textarea"
                Width="97.5%"></asp:TextBox>
        </fieldset>
        <fieldset>
            <asp:Button CssClass="button" ID="btnVoid" Text="Void" OnClick="btnVoid_Click" runat="server"
                CausesValidation="False" />
        </fieldset>
    </div>
    <br />
    <div id="dialog">
        <!-- Messages are shown when a link with these attributes are clicked: href="#messages" rel="modal"  -->
        <h4>
            Input new Voucher date</h4>
        <fieldset>
            <asp:TextBox runat="server" ID="txt_VoucherDateClone" CssClass="text-input datepicker"
                Width="97.5%"></asp:TextBox>
        </fieldset>
        <fieldset>
            <asp:Button CssClass="button" ID="btn_Clone" Text="Clone" OnClick="btnClone_Click"
                runat="server" CausesValidation="False" />
        </fieldset>
    </div>
    <div id="message" style="display: none">
        <h4>
            Voucher clone success.</h4>
    </div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div style="text-align: center;">
                <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"
                    DynamicLayout="true">
                    <ProgressTemplate>
                        <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0;
                            right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
                            <img alt="progress" src="resources/images/leaf_loader.gif" style="padding: 10px;
                                position: fixed; top: 45%; left: 50%;" />
                        </div>
                    </ProgressTemplate>
                </asp:UpdateProgress>
            </div>
            <asp:Panel runat="server" ID="pn_PaymentDetailsAdd" Width="100%" Visible="false"
                DefaultButton="btnSave" DefaultFocus="dataDrugId">
                <table style="width: 1100px">
                    <tr>
                        <td colspan="7">
                            <h3>
                                Add Details
                            </h3>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Account
                        </td>
                        <td>
                            Description
                        </td>
                        <td>
                            Description (VN)
                        </td>
                        <td>
                            Money Type
                        </td>
                        <td>
                            Amount
                        </td>
                        <td>
                            Debit / Credit
                        </td>
                        <td>
                            T0
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <data:EntityDropDownList runat="server" ID="dataAccountCode" DataSourceID="" DataTextField="AccntName"
                                DataValueField="AccntCode" ValidationGroup="Detail" TabIndex="7" AppendNullItem="True"
                                NullItemText="<.. Please select ..>" />
                            <%--<data:EntityDropDownList runat="server" ID="dataDrugId" DataSourceID="DrugIdDrugDispoDataSource"
                                DataTextField="DrugName" DataValueField="DrugId" AppendNullItem="true" Required="true"
                                ValidationGroup="Detail" TabIndex="10" NullItemText="< Please Choose ...>" ErrorText="Required"
                                onchange="GetDrug($(this).val());" onkeypress="disableSubmit();" />--%>
                            <data:SunAccountCodeDataSource ID="SunAccountCodeDataSource" runat="server" SelectMethod="GetPaged"
                                Sort="AccntName ASC" />
                        </td>
                        <td>
                            <asp:TextBox runat="server" ID="dataDescription" CssClass="text-input" MaxLength="25"
                                TabIndex="7" onblur="javascript:TranslateText(this)" />
                        </td>
                        <td>
                            <asp:TextBox runat="server" ID="dataDescriptionVN" CssClass="text-input" MaxLength="100"
                                TabIndex="7" />
                        </td>
                        <td>
                            <asp:DropDownList runat="server" ID="dataMoneyType" TabIndex="7">
                                <asp:ListItem Text="VND" Selected="True"></asp:ListItem>
                                <asp:ListItem Text="USD"></asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td>
                            <input type="text" runat="server" id="dataAmount" class="text-input" style="width: 80px"
                                tabindex="8" value="" />
                        </td>
                        <td>
                            <asp:DropDownList runat="server" ID="dataDebitCredit" TabIndex="8">
                                <asp:ListItem Text="Debit" Selected="True"></asp:ListItem>
                                <asp:ListItem Text="Credit"></asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td>
                            <data:EntityDropDownList runat="server" ID="dataT0" CssClass="text-input" TabIndex="8"
                                NullItemText="<.. Please select ..>" AppendNullItem="True" DataTextField="Description"
                                DataValueField="Value" />
                        </td>
                    </tr>
                </table>
                <table style="width: 1100px">
                    <tr>
                        <td>
                            T1
                        </td>
                        <td>
                            T2
                        </td>
                        <td>
                            T3
                        </td>
                        <td>
                            T4
                        </td>
                        <td>
                            T5
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <data:EntityDropDownList runat="server" ID="dataT1" CssClass="text-input" TabIndex="8"
                                NullItemText="<.. Please select ..>" AppendNullItem="True" DataTextField="Description"
                                DataValueField="Value" />
                        </td>
                        <td>
                            <data:EntityDropDownList runat="server" ID="dataT2" CssClass="text-input" TabIndex="8"
                                NullItemText="<.. Please select ..>" AppendNullItem="True" DataTextField="Description"
                                DataValueField="Value" />
                        </td>
                        <td>
                            <data:EntityDropDownList runat="server" ID="dataT3" CssClass="text-input" TabIndex="8"
                                NullItemText="<.. Please select ..>" AppendNullItem="True" DataTextField="Description"
                                DataValueField="Value" />
                        </td>
                        <td>
                            <input type="text" runat="server" id="dataT4" class="text-input" tabindex="12" style="width: 80px" />
                        </td>
                        <td>
                            <input type="text" runat="server" id="dataT5" class="text-input" tabindex="12" style="width: 80px" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <div id="div_DetailsError" runat="server">
                            </div>
                            <br />
                            <asp:Button ID="btnSave" Text="Add Detail" CssClass="button" TabIndex="13" runat="server"
                                OnClick="btnSave_Click" ValidationGroup="Detail" />
                            <asp:Button ID="btnCancel" Text="Cancel" CssClass="button" TabIndex="14" Visible="False"
                                OnClick="btnCancel_Click" CausesValidation="False" runat="server" />
                        </td>
                        <td colspan="2">
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <br />
            <h4>
                Payment Details</h4>
            <data:EntityGridView ID="GridViewPaymentDetail1" runat="server" AutoGenerateColumns="False"
                AllowSorting="True" OnDataBound="GridViewPaymentDetail1_DataBound" DataSourceID="PaymentDetailDataSource1"
                DataKeyNames="PaymentDetailId" AllowMultiColumnSorting="false" DefaultSortColumnName=""
                OnRowCommand="GridViewPaymentDetail1_RowCommand" DefaultSortDirection="Ascending"
                ExcelExportFileName="Export_PaymentDetail.xls" Visible='<%# FormView1.DefaultMode != FormViewMode.Insert %>'
                ShowFooter="True" TabIndex="26">
                <FooterStyle BackColor="Red" Font-Bold="True" ForeColor="White" HorizontalAlign="Right" />
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton runat="server" ID="btn_Edit" CommandName="DetailEdit" Visible='<%#IsEditable%>'
                                CausesValidation="False" CommandArgument='<%#Eval("PaymentDetailId") %>'>Edit</asp:LinkButton>
                            <asp:LinkButton runat="server" ID="btn_Clone" CommandName="Clone" Visible='<%#IsEditable%>'
                                CausesValidation="False" CommandArgument='<%#Eval("PaymentDetailId") %>'>Clone</asp:LinkButton>
                            <asp:LinkButton runat="server" ID="btn_Delete" CommandName="Delete" Visible='<%#IsEditable%>'
                                CausesValidation="False">Delete</asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="AccountCode" HeaderText="Account Code" SortExpression="[AccountCode]" />
                    <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="[Description]" />
                    <asp:BoundField DataField="MoneyType" HeaderText="Money Type" SortExpression="[MoneyType]"
                        FooterText="Total:" />
                    <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="[Amount]"
                        DataFormatString="{0:#,##0.00}">
                        <ItemStyle HorizontalAlign="Right" />
                    </asp:BoundField>
                    <asp:BoundField DataField="DebitCredit" HeaderText="Debit/Credit" SortExpression="[DebitCredit]" />
                    <asp:BoundField DataField="T0" HeaderText="T0" SortExpression="[T0]" />
                    <asp:BoundField DataField="T1" HeaderText="T1" SortExpression="[T1]" />
                    <asp:BoundField DataField="T2" HeaderText="T2" SortExpression="[T2]" />
                    <asp:BoundField DataField="T3" HeaderText="T3" SortExpression="[T3]" />
                    <asp:BoundField DataField="T4" HeaderText="T4" SortExpression="[T4]" />
                    <asp:BoundField DataField="T5" HeaderText="T5" SortExpression="[T5]" />
                </Columns>
                <EmptyDataTemplate>
                </EmptyDataTemplate>
            </data:EntityGridView>
            <data:PaymentDetailDataSource ID="PaymentDetailDataSource1" runat="server" SelectMethod="GetPaged"
                EnableDeepLoad="True">
                <DeepLoadProperties Method="IncludeChildren" Recursive="False">
                    <Types>
                        <data:PaymentDetailProperty Name="Payment" />
                    </Types>
                </DeepLoadProperties>
                <Parameters>
                    <data:SqlParameter Name="WhereClause" UseParameterizedFilters="False">
                        <Filters>
                            <data:PaymentDetailFilter Column="PaymentId" QueryStringField="PaymentId" ComparisionType="Equals" />
                        </Filters>
                    </data:SqlParameter>
                    <data:SqlParameter Name="OrderBy" DefaultValue="PaymentDetailId DESC">
                    </data:SqlParameter>
                </Parameters>
            </data:PaymentDetailDataSource>
            <br />
        </ContentTemplate>
    </asp:UpdatePanel>
    <br />
</asp:Content>
